﻿namespace TimeManagement.DataAccess.Configurations
{
    using Models;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity.Infrastructure.Annotations;
    using System.Data.Entity.ModelConfiguration;

    public class UserConfiguration : EntityTypeConfiguration<User>
    {
        public UserConfiguration()
        {
            ToTable("Users", "tms");

            Property(u => u.UserId).IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(u => u.UserName).IsRequired()
                .HasMaxLength(128)
                .HasColumnAnnotation("Index", new IndexAnnotation(
                    new IndexAttribute("UserName") { IsUnique = true }
                    ));
            Property(u => u.UserPass).IsRequired()
                .HasMaxLength(32);
            Property(u => u.Email).IsRequired()
                .HasMaxLength(128)
                .HasColumnAnnotation("Index", new IndexAnnotation(
                    new IndexAttribute("UserEmail") { IsUnique = true }
                    ));
            Property(u => u.Roles).IsRequired()
                .HasMaxLength(512);
        }
    }
}
